let s:suite = themis#suite('event')
let s:assert = themis#helper('assert')

function! s:suite.before_each()
  let b:calendar = {'day': {-> {'get_ymd': {-> [2023, 3, 2]}, 'get_year': {-> 2023}}}}
endfunction

function! s:suite.parse_title()
  let tests = [
        \ ['hello', 'big', 'hello', '2023-03-02', '2023-03-03', {}],
        \ ['2022-10-5 hello', 'big', 'hello', '2022-10-05', '2022-10-06', {}],
        \ ['  2022/10/5  hello  ', 'big', 'hello  ', '2022-10-05', '2022-10-06', {}],
        \ ["\t2022-10-5 hello", 'big', 'hello', '2022-10-05', '2022-10-06', {}],
        \ ['10-5-2022 hello', 'little', 'hello', '2022-05-10', '2022-05-11', {}],
        \ ['10-5-2022 hello', 'middle', 'hello', '2022-10-05', '2022-10-06', {}],
        \ ['10/5 hello', 'big', 'hello', '2023-10-05', '2023-10-06', {}],
        \ ['10-5 hello', 'little', 'hello', '2023-05-10', '2023-05-11', {}],
        \ ['10-5 hello', 'middle', 'hello', '2023-10-05', '2023-10-06', {}],
        \ ['10-5-6 hello', 'big', 'hello', '2023-10-05', '2023-10-07', {}],
        \ ['5-10-6 hello', 'little', 'hello', '2023-10-05', '2023-10-07', {}],
        \ ['10-5-6 hello', 'middle', 'hello', '2023-10-05', '2023-10-07', {}],
        \ ['2022-10-5 - 2022-10-11 hello', 'big', 'hello', '2022-10-05', '2022-10-12', {}],
        \ ["2022/10/5\t-\t2022/10/11 hello", 'big', 'hello', '2022-10-05', '2022-10-12', {}],
        \ ['2022/10/5-2022/10/11 hello', 'big', 'hello', '2022-10-05', '2022-10-12', {}],
        \ ['10-5-2022 - 10-11-2022 hello', 'middle', 'hello', '2022-10-05', '2022-10-12', {}],
        \ ['10/5-10/11 hello', 'big', 'hello', '2023-10-05', '2023-10-12', {}],
        \ ['5-10-11-10 hello', 'little', 'hello', '2023-10-05', '2023-10-12', {}],
        \ ['10-5-10-11 hello', 'middle', 'hello', '2023-10-05', '2023-10-12', {}],
        \ ['12/31 - 1/3 hello', 'big', 'hello', '2023-12-31', '2024-01-04', {}],
        \ ['12/31 - 3/5 hello', 'big', 'hello', '2022-12-31', '2023-03-06', {}],
        \ ['2022-10-5 10:11:12-11:12:13 hello', 'big', 'hello', '2022-10-05T10:11:12', '2022-10-05T11:12:13', {}],
        \ ['2022-10-5 1:2 - 3:4 hello', 'big', 'hello', '2022-10-05T01:02:00', '2022-10-05T03:04:00', {}],
        \ [' 2022-10-5 24:01-29:59 hello', 'big', 'hello', '2022-10-06T00:01:00', '2022-10-06T05:59:00', {}],
        \ ['10-5 1:2 - 10-6 3:4 hello', 'big', 'hello', '2023-10-05T01:02:00', '2023-10-06T03:04:00', {}],
        \ ['10-5 1:2 - 10-6 3:4 hello', 'little', 'hello', '2023-05-10T01:02:00', '2023-06-10T03:04:00', {}],
        \ ['10-5 1:2 - 10-6 3:4 hello', 'middle', 'hello', '2023-10-05T01:02:00', '2023-10-06T03:04:00', {}],
        \ ['1:2 - 3:4 hello', 'big', 'hello', '2023-03-02T01:02:00', '2023-03-02T03:04:00', {}],
        \ [' 10:12 - 11:12 hello', 'little', 'hello', '2023-03-02T10:12:00', '2023-03-02T11:12:00', {}],
        \ ['12:0 - 13:0 hello', 'middle', 'hello', '2023-03-02T12:00:00', '2023-03-02T13:00:00', {}],
        \ ['25:2-26:4 hello', 'big', 'hello', '2023-03-03T01:02:00', '2023-03-03T02:04:00', {}],
        \ ['12/31 23:00-25:00 hello', 'big', 'hello', '2023-12-31T23:00:00', '2024-01-01T01:00:00', {}],
        \ [' 10/5 - 10/7 3weeks hello', 'big', 'hello', '2023-10-05', '2023-10-08', {'week':3}],
        \ [' 5weeks hello', 'big', 'hello', '2023-03-02', '2023-03-03', {'week':5}],
        \ ['  10/12 16:00 - 10/12 20:00  12days  hello', 'big', 'hello', '2023-10-12T16:00:00', '2023-10-12T20:00:00', {'day':12}],
        \ ]
  for [src, endian; expected] in tests
    let message = printf('src: %s, endian: %s', src, endian)
    let g:calendar_date_endian = endian
    call s:assert.equals(calendar#view#event#parse_title(src, 1), expected, message)
  endfor
endfunction
